const Stream = require('node-rtsp-stream');
const express = require('express');

let stream = new Stream({
  name: 'name',
  streamUrl: 'rtsp://127.0.0.1:8554/test',
  wsPort: 9999,
  ffmpegOptions: { // options ffmpeg flags
    '-stats': '', // an option with no neccessary value uses a blank string
    '-r': 30 // options with required values specify the value after the key
  }
})

const app = express();

app.get('/',(req,res) =>{
    const html = `
    <html>
<body>
<canvas id="canvas" width="1024" height="768"></canvas>
</body>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsmpeg/0.1/jsmpg.js"></script>
<script type="text/javascript">
    var client = new WebSocket('ws://localhost:9999');
    var canvas = document.querySelector('canvas');
    var player = new jsmpeg(client, {
    canvas: canvas 
    });
</script>
</html>`;
    res.write(html);
    res.end();
});

app.listen(3000,()=>console.log('server on 3000.'));